package bpce.Entry;

import plugin.bpce.modelo.BPCEResult;

import coppeer.agency.AgencyId;
import coppeer.cell.Cell;
import coppeer.cell.Entry;

public class QueryResultEntry implements Entry{
	
	private static final long serialVersionUID = -5799466027353973638L;
	private String query;
	private BPCEResult[] queryResult;
	private AgencyId source;
	
	public boolean afterPropagation() {
		return false;
	}
	
	public boolean beforePropagation() {
		return false;
	}
	
	public Entry generatePropagation(Cell neighbor) {
		return null;
	}
	
	public long getPropagationLease(Cell neighbor) {
		return 0;
	}
	
	public String getQuery(){
		return this.query;
	}

	public BPCEResult[] getResult(){
		return this.queryResult;
	}

	public boolean matches(Entry template) {
		try{
			QueryResultEntry tmpl = (QueryResultEntry) template;
			if (tmpl.queryResult != null)
				if (!tmpl.queryResult.equals(queryResult)) 
					return false;
				else if (!tmpl.query.equals(query)) 
					return false;
				else if (!tmpl.source.equals(source)) 
					return false;
			return true;
		}catch(Exception e){
			return false;
		}
	}

	public void setAgency (AgencyId agency){
		this.source = agency;		
	}

	public void setBPCEREsult(BPCEResult[] queryResult){
		this.queryResult = queryResult;
	}

	public void setQuery (String Assunto){
		this.query = Assunto;
	}
}